package com.dower.clothing.controller;

import java.util.List;

import com.dower.common.annotation.Log;
import com.dower.common.core.controller.BaseController;
import com.dower.common.core.domain.AjaxResult;
import com.dower.common.core.page.TableDataInfo;
import com.dower.common.enums.BusinessType;
import com.dower.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.dower.clothing.domain.NntPlatformCoupon;
import com.dower.clothing.service.INntPlatformCouponService;

/**
 * 平台优惠券Controller
 * 
 * @author dower
 * @date 2020-08-31
 */
@Controller
@RequestMapping("/clothing/coupon")
public class NntPlatformCouponController extends BaseController
{
    private String prefix = "clothing/coupon";

    @Autowired
    private INntPlatformCouponService nntPlatformCouponService;

    @RequiresPermissions("clothing:coupon:view")
    @GetMapping()
    public String coupon()
    {
        return prefix + "/coupon";
    }

    /**
     * 查询平台优惠券列表
     */
    @RequiresPermissions("clothing:coupon:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(NntPlatformCoupon nntPlatformCoupon)
    {
        startPage();
        List<NntPlatformCoupon> list = nntPlatformCouponService.selectNntPlatformCouponList(nntPlatformCoupon);
        return getDataTable(list);
    }

    /**
     * 导出平台优惠券列表
     */
    @RequiresPermissions("clothing:coupon:export")
    @Log(title = "平台优惠券", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(NntPlatformCoupon nntPlatformCoupon)
    {
        List<NntPlatformCoupon> list = nntPlatformCouponService.selectNntPlatformCouponList(nntPlatformCoupon);
        ExcelUtil<NntPlatformCoupon> util = new ExcelUtil<NntPlatformCoupon>(NntPlatformCoupon.class);
        return util.exportExcel(list, "coupon");
    }

    /**
     * 新增平台优惠券
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存平台优惠券
     */
    @RequiresPermissions("clothing:coupon:add")
    @Log(title = "平台优惠券", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(NntPlatformCoupon nntPlatformCoupon)
    {
        return toAjax(nntPlatformCouponService.insertNntPlatformCoupon(nntPlatformCoupon));
    }

    /**
     * 修改平台优惠券
     */
    @GetMapping("/edit/{numId}")
    public String edit(@PathVariable("numId") Long numId, ModelMap mmap)
    {
        NntPlatformCoupon nntPlatformCoupon = nntPlatformCouponService.selectNntPlatformCouponById(numId);
        mmap.put("nntPlatformCoupon", nntPlatformCoupon);
        return prefix + "/edit";
    }

    /**
     * 修改保存平台优惠券
     */
    @RequiresPermissions("clothing:coupon:edit")
    @Log(title = "平台优惠券", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(NntPlatformCoupon nntPlatformCoupon)
    {
        return toAjax(nntPlatformCouponService.updateNntPlatformCoupon(nntPlatformCoupon));
    }

    /**
     * 删除平台优惠券
     */
    @RequiresPermissions("clothing:coupon:remove")
    @Log(title = "平台优惠券", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(nntPlatformCouponService.deleteNntPlatformCouponByIds(ids));
    }
}
